package com.jungle.web.controller.common;

import cn.dev33.satoken.annotation.SaIgnore;
import com.jungle.common.constant.UserConstants;
import com.jungle.common.core.domain.entity.SysMenu;
import com.jungle.system.service.ISysMenuService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 导航首页
 *
 * @author Lion Li
 */
@SaIgnore
@Slf4j
@Validated
@RequiredArgsConstructor
@Controller
public class IndexController {

    private final ISysMenuService sysMenuService;


    @GetMapping("/")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        List<SysMenu> sysMenus = sysMenuService.selectMenuList(1l);
        List<SysMenu> systems = sysMenus.stream()
            .filter(m -> UserConstants.TYPE_SYSTEM.equals(m.getMenuType()))
            .filter(m -> UserConstants.MENU_NORMAL.equals(m.getVisible()))
            .sorted(Comparator.comparing(SysMenu::getOrderNum)).collect(Collectors.toList());
        modelAndView.setViewName("index");
        modelAndView.addObject("systems", systems);
        return modelAndView;
    }
}
